Freezes or resumes the frame - Step Begin/Alarms/Buttons/Step/Movement/Step End stop running while paused, but Draw and the debug overlay keep running every frame regardless.
game_pause(paused, keep_animating = false)| Name | Type |
|---|---|
paused | bool |
keep_animating | bool (can be left out; then it is false) |
Nothing.
Freezes or resumes the frame. While the game is paused, Step Begin, Alarms, Button events, Step, movement and Step End all stop running. Draw, Draw GUI and the debug overlay keep running every frame. That is what lets a pause-menu object draw itself over a world that has otherwise frozen.
Button events are asleep while the game is paused. A Button Pressed event can pause the game, but it can never resume it, because it does not run again until the game is running. So a pause menu that pauses and resumes from a Button Pressed event pauses once and then gets stuck for good. The fix is to read the buttons that resume and steer the menu inside Draw GUI, the one event that is still awake. btn_pressed works there exactly as it does in Step.
Sprite animation and animated tiles stop too, so a paused game really is still. That comes from a box in Project Settings, Stop animations on pause, which is ticked in every project. A sprite holds the picture it is showing and carries on from it when the game resumes; the sprites in your pause menu hold still as well, so draw anything that should move in the menu with game_frame or wave, which never stop. The same freeze applies while a cutscene or a room transition has stopped Step. Untick the box and sprites and tiles keep animating behind the menu. See Project settings.
To keep animation running through a pause, pass true as the optional second argument, keep_animating: game_pause(true, true). Left out it is false, which freezes, so game_pause(true) stays a still pause. The value of the last call stands (also for a cutscene or room transition that comes next), and game_pause(false) puts the freeze back.
Pausing is a project decision, not the engine's own: nothing pauses on its own, and nothing is reserved as "the pause button" until a project calls this itself.
if (btn_pressed(BTN_START)) {
game_pause(true);
}The Step event opens the pause. It only runs while the game is not paused, which is exactly when a pause should be able to start.
if (game_paused()) {
draw_text(4, 4, "PAUSED");
if (btn_pressed(BTN_START)) {
game_pause(false);
}
}The Draw GUI event is the menu while it is up. It draws the label and watches for START to resume, because Draw GUI is the only one of these two events that still runs while paused.
One trap remains in this pair. btn_pressed stays true for the whole frame the press happens on. The Step above pauses on that frame, and later that same frame the Draw GUI sees the same press and resumes straight away, so the menu never appears. A real menu keeps a flag such as just_opened, set when it opens and cleared in Draw GUI, to ignore that first frame. The pause_menu example project does exactly this, with a working menu built around it.
A pause is a project decision, not the engine’s. Button events do not run while paused, so a Button Pressed handler can pause the game but never resume it. Read btn_pressed in Draw GUI to resume. Sprite animation (and the Animation End event) and animated tiles hold still too, and also while a cutscene or a room transition has stopped Step: that is the default, because Project Settings has a box, Stop animations on pause, ticked in every project (untick it and they play on behind the menu). Pass true as the second argument, keep_animating, to let them play on through this pause, a cutscene or a room transition; the value of the last call stands, so game_pause(false) puts the freeze back.